package com.ruoyi.project.price.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.price.domain.BinsPriceRule;
import com.ruoyi.project.price.service.IBinsPriceRuleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 价格规则Controller
 * 
 * @author administrator
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/price/rule")
public class BinsPriceRuleController extends BaseController
{
    @Autowired
    private IBinsPriceRuleService binsPriceRuleService;

    /**
     * 查询价格规则列表
     */
    @PreAuthorize("@ss.hasPermi('price:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinsPriceRule binsPriceRule)
    {
        startPage();
        if (null==binsPriceRule.getDeptId()) {
            binsPriceRule.setDeptId(getCommonDeptId());
        }
        List<BinsPriceRule> list = binsPriceRuleService.selectBinsPriceRuleList(binsPriceRule);
        return getDataTable(list);
    }

    /**
     * 导出价格规则列表
     */
    @PreAuthorize("@ss.hasPermi('price:rule:export')")
    @Log(title = "价格规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinsPriceRule binsPriceRule)
    {
        List<BinsPriceRule> list = binsPriceRuleService.selectBinsPriceRuleList(binsPriceRule);
        ExcelUtil<BinsPriceRule> util = new ExcelUtil<BinsPriceRule>(BinsPriceRule.class);
        util.exportExcel(response, list, "价格规则数据");
    }

    /**
     * 获取价格规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('price:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(binsPriceRuleService.selectBinsPriceRuleById(id));
    }

    /**
     * 新增价格规则
     */
    @PreAuthorize("@ss.hasPermi('price:rule:add')")
    @Log(title = "价格规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinsPriceRule binsPriceRule)
    {
        return toAjax(binsPriceRuleService.insertBinsPriceRule(binsPriceRule));
    }

    /**
     * 修改价格规则
     */
    @PreAuthorize("@ss.hasPermi('price:rule:edit')")
    @Log(title = "价格规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinsPriceRule binsPriceRule)
    {
        return toAjax(binsPriceRuleService.updateBinsPriceRule(binsPriceRule));
    }

    /**
     * 删除价格规则
     */
    @PreAuthorize("@ss.hasPermi('price:rule:remove')")
    @Log(title = "价格规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(binsPriceRuleService.deleteBinsPriceRuleByIds(ids));
    }
}
